<?php

namespace app\admin\service;

use think\facade\Cache;
use think\Model;

class CurdService
{
    protected Model $model;

    public function __construct(Model $model){
        $this->model = $model;
    }


//    public function options(){
//        $table = $this->model->getTable();
//        $options = Cache::get($table.'_options', null);
//        if (!$options){
//            $options = $this->model->scope('valid')->select();
//        }
//        return $options;
//    }

    public function create($data){
        // 清除缓存
        Cache::tag($this->model->getTable())->clear();
        $class = get_class($this->model);
        return $class::create($data);
    }

    public function update($data, $where){
        // 清除缓存
        Cache::tag($this->model->getTable())->clear();
        $class = get_class($this->model);
        return $class::update($data, $where);
    }

    public function destroy($ids, bool $isForce=false){
        // 清除缓存
        Cache::tag($this->model->getTable())->clear();
        $class = get_class($this->model);
        return $class::destroy($ids, $isForce);

    }

}
